import {
    checkUpdateVersion,
    algorithm
} from './utils/util'
// app.js
App({

    onLaunch() {
        console.log(__wxConfig)
        const version = __wxConfig.envVersion;
        switch (version) {
            // 开发
            case 'develop':
                this.globalData.apihost = 'https://jianxiangjinjiren.com'
                break;
                // 线上
            case 'release':
                this.globalData.apihost = 'https://jianxiangjinjiren.com'
                break;
            default:
                this.globalData.apihost = 'https://jianxiangjinjiren.com'
                break;
        }
        // http://192.168.10.252
        // http://jianxiangjinjiren.com
        checkUpdateVersion()
        this.globalData.algorithm = algorithm()

        let that = this;
        wx.request({
            url: 'https://pv.sohu.com/cityjson?ie=utf-8',
            success(res) {
                let data = JSON.parse(res.data.split("=")[1].split(";")[0]);
                that.globalData.ip = data.cip
            }
        })

        // 检查用户是否已同意隐私政策
        const privacyAgreed = wx.getStorageSync('privacyAgreed');
        if (!privacyAgreed) {
            // 未同意，记录需要弹窗（在首页显示）
            this.globalData.needShowPrivacyModal = true;
        } else {
            this.globalData.needShowPrivacyModal = false;
        }
    },
    globalData: {
        userInfo: null,
        needShowPrivacyModal: false // 控制弹窗显示的全局变量
    },
})